﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sitecore.Models;

namespace Sitecore.Controllers
{


    public class HomeController : Controller
    {
        private int ItemsPerPage = 10;

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult List(bool SortByBookTitle = true, int pageNumber = 0)
        {
            List<Book> list = new List<Book>();
            try
            {
                ViewData["pageNumber"] = pageNumber;
                ViewData["pageSize"] = ItemsPerPage;
                ViewData["itemsCount"] = DataProject.DBController.BookCount();

                var bookList = DataProject.DBController.GetListOfBook(ItemsPerPage, pageNumber, SortByBookTitle);
                foreach (DataProject.Book domainBook in bookList)
                {
                    list.Add(Book.FromDbModel(domainBook));
                }
            }
            catch { }
            return View(list);
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult Details(int Id)
        {
            return View(Book.FromDbModel(DataProject.DBController.GetBookById(Id)));
        }
    }
}
